package cn.ssm.petadopt.controller;

import cn.ssm.petadopt.dto.DouPassword;
import cn.ssm.petadopt.dto.PwdSettingDTO;
import cn.ssm.petadopt.dto.ResisterDTO;
import cn.ssm.petadopt.dto.UserLoginDTO;
import cn.ssm.petadopt.entity.User;
import cn.ssm.petadopt.service.UserService;
import cn.ssm.petadopt.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Autheor: Sun俊仪
 * @Date: 2022 2022/12/17 11:22
 * @Name: PetSystem
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    // 判断账号
    @RequestMapping("judgeUsername")
    public ResponseResult judgeName(String userName){
        ResponseResult responseResult = userService.judgeUserName(userName);
        return  responseResult;
    }

    // 判断密码
    @RequestMapping("judgePassword")
    public ResponseResult judgePwd(DouPassword douPassword){
        ResponseResult responseResult = userService.judgePwd(douPassword);
        return responseResult;
    }

    // 注册
    @RequestMapping("register")
    public ResponseResult regist(@RequestBody ResisterDTO resisterDTO , HttpSession session){
        System.out.println("resisterDTO = " + resisterDTO);
        ResponseResult responseResult = userService.registerUser(resisterDTO, session);
        return responseResult;
    }

    // 用户登录
    @RequestMapping("loginUser")
    public ResponseResult loginU(@RequestBody UserLoginDTO userLoginDTO , HttpSession session){
        System.out.println("userLoginDTO = " + userLoginDTO);
        ResponseResult responseResult = userService.loginU(userLoginDTO,session);
        return responseResult;
    }

    // 修改个人信息数据回显
    @RequestMapping("showUserSetting")
    public ResponseResult showUserSet(String userName){
        System.out.println("userName = " + userName);
        ResponseResult responseResult = userService.selectShowSetting(userName);
        return responseResult;
    }

    // 修改个人信息
    @RequestMapping("updateUser")
    public ResponseResult updateU(@RequestBody User user){
        System.out.println("user = " + user);
        ResponseResult responseResult = userService.updateU(user);
        return responseResult;
    }

    // 修改个人密码
    @RequestMapping("pwdSetting")
    public ResponseResult pwdSet(@RequestBody PwdSettingDTO pwdSettingDTO,HttpSession session){
        System.out.println("pwdSettingDTO = " + pwdSettingDTO);
        ResponseResult responseResult = userService.updatePwdSet(pwdSettingDTO,session);
        return responseResult;
    }




}
